home *** CD-ROM | disk | FTP | other *** search
Wrap
(*************************************************** Ant Movie Catalog importation script www.antp.be/software/moviecatalog/ [Infos] Authors=JanC (<link>amc-script@janc.cjb.net</link>) Title=MovieMeter.nl Description=MovieMeter.nl import script Site=www.moviemeter.nl Language=NL Version= Requires=3.5.0 Comments= Now works with the new site !!| partially based on other import scripts| corrections by <link>rolandb5@hotmail.com</link>| License=This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. | GetInfo=1 [Options] ***************************************************) program MovieMeter; var MovieName: string; procedure AnalyzeMoviePage(Address: string); var Page: TStringList; Line, Value: string; LineNr: Integer; I: Integer; BeginPos, EndPos: Integer; begin // get movie page Page := TStringList.Create; Page.Text := GetPage(Address); // get URL SetField(fieldURL, Address); // find line with titles & year LineNr := 0; repeat LineNr := LineNr + 1; Line := Page.GetString(LineNr); until Pos('<p class="kop">', Line) > 0; // get original(?) title BeginPos := Pos('<p class="kop">', Line); Delete(Line, 1, BeginPos-1); BeginPos := Pos('<p class="kop">', Line) + Length('<p class="kop">'); EndPos := Pos('(', Line) - Length(' '); Value := Copy(Line, BeginPos, EndPos - BeginPos); HTMLDecode(Value); SetField(fieldOriginalTitle, Value); Delete(Line, 1, EndPos); // get year BeginPos := Pos('(', Line) + Length('('); EndPos := pos(')', Line); Value := Copy(Line, BeginPos, EndPos - BeginPos); HTMLDecode(Value); SetField(fieldYear, Value); // get first alternative title??? LineNr := LineNr + 1; Line := Page.GetString(LineNr); BeginPos := Pos('Alternatieve titel:', Line) + Length(' Alternatieve titel:'); if BeginPos > 0 then begin EndPos := pos('</b>', Line); Value := Copy(Line, BeginPos, EndPos - BeginPos); HTMLDecode(Value); SetField(fieldTranslatedTitle, Value); end; // find line with country, cat & length repeat LineNr := LineNr + 1; Line := Page.GetString(LineNr); until Pos('geregisseerd door', Line) > 0; // get country BeginPos := 1; EndPos := Pos('<br>', Line); Value := StringReplace(Copy(Line, BeginPos, EndPos - BeginPos), #9, ''); HTMLDecode(Value); SetField(fieldCountry, Value); Delete(Line, 1, EndPos + Length('<br>') - 1); // get category BeginPos := 1; EndPos := Pos('<br>', Line); Value := Copy(Line, BeginPos, EndPos - BeginPos); HTMLDecode(Value); SetField(fieldCategory, Value); Delete(Line, 1, EndPos + Length('<br>') - 1); // get length BeginPos := 1; EndPos := Pos(' minuten <br>', Line); Value := Copy(Line, BeginPos, EndPos - BeginPos); HTMLDecode(Value); SetField(fieldLength, Value); // find line with director & actors repeat LineNr := LineNr + 1; Line := Page.GetString(LineNr); until Pos('<a href="?regisseur=', Line) > 0; // get director BeginPos := Pos('">', Line) + Length('">'); EndPos := Pos('</a>', Line); Value := Copy(Line, BeginPos, EndPos - BeginPos); HTMLDecode(Value); SetField(fieldDirector, Value); Delete(Line, 1, EndPos-1); // get actors BeginPos := Pos('<br>met ', Line) + Length('<br>met '); EndPos := Pos('</p><p>', Line); Value := StringReplace(Copy(Line, BeginPos, EndPos - BeginPos), #9, ''); HTMLDecode(Value); SetField(fieldActors, Trim(Value)); Value := ''; repeat // get line with description LineNr := LineNr + 1; Line := Page.GetString(LineNr); if Pos('</p>', Line) = 0 then begin Value := Value + Line; end; // get description if Pos('</p>', Line) > 0 then begin BeginPos := 1; EndPos := Pos('</p>', Line); Value := Value + Copy(Line, BeginPos, EndPos - BeginPos); end; HTMLDecode(Value); until Pos('</p>', Line) > 0; Value := StringReplace(Value, #9, ''); SetField(fieldDescription, Value); // find line with cover picture repeat LineNr := LineNr + 1; Line := Page.GetString(LineNr); until Pos('<img src="images/covers/', Line) > 0; // get cover picture BeginPos := Pos('<img src="', Line) + Length('<img src="'); EndPos := Pos('" ', Line); Value := Copy(Line, BeginPos, EndPos - BeginPos); GetPicture('http://www.moviemeter.nl/' + Value); // find line with rating repeat LineNr := LineNr + 1; Line := Page.GetString(LineNr); until Pos('<td class="stembody">', Line) > 0; LineNr := LineNr + 1; Line := Page.GetString(LineNr); // get average rating (range 0.00-5.00 on the site, range 0-10 in AMC) BeginPos := Pos('<br>', Line) + Length('<br>'); EndPos := Pos(' gemiddeld', Line); Value := Copy(Line, BeginPos, EndPos - BeginPos); I := StrToInt(Copy(Value, 1, 1), 0) * 100 + StrToInt(Copy(Value, 3, 2), 0); Value := IntToStr(Round(I/50)); SetField(fieldRating, Value); //DisplayResults; Page.Free; end; procedure AnalyzeResultsPage(Address: string); var Page: TStringList; Line: string; MovieAddress: string; LineNr: Integer; MovieTitle: string; StartPos, EndPos: Integer; begin // get results page Page := TStringList.Create; Page.Text := GetPage(Address); // get redirect javascript Line := Page.GetString(Page.Count-1); // if only 1 movie found --> redirect to movie page if Pos('location.replace("?film=', Line) <> 0 then begin StartPos := Pos('?film=', Line); EndPos := Pos('");</script>', Line); MovieAddress := 'http://moviemeter.nl/' + Copy(Line, StartPos, EndPos - StartPos); AnalyzeMoviePage(MovieAddress); end // more than 1 movie found else if Pos('location.href = "?searchresults"', Line) <> 0 then begin PickTreeClear; // get results page Page.Text := GetPage('?searchresults'); // find line with results LineNr := 0; repeat LineNr := LineNr + 1; Line := Page.GetString(LineNr); until Pos('<!--m-->', Line) > 0; // find individual results delimited by <!--m--> & <!--n-->' StartPos := Pos('<!--m-->', Line); while StartPos > 0 do begin Delete(Line, 1, StartPos-1); StartPos := Pos('<!--m-->', Line) + Length('<!--m--><a href="'); EndPos := Pos('">', Line); MovieAddress := Copy(Line, StartPos, EndPos - StartPos); StartPos := Pos('">', Line) + Length('"><b>'); EndPos := Pos('<br>', Line); MovieTitle := Copy(Line, StartPos, EndPos - StartPos); HTMLRemoveTags(MovieTitle); HTMLDecode(Movietitle); PickTreeAdd(MovieTitle, 'http://www.moviemeter.nl/' + MovieAddress); Delete(Line, 1, EndPos-1); StartPos := Pos('<!--m-->', Line); end; // if user picks a movie from the results list, import movie details if PickTreeExec(Address) then AnalyzeMoviePage(Address); end // no movies found else begin ShowMessage('Geen zoekresultaat voor "'+MovieName+'".'); end; Page.Free; end; begin if CheckVersion(3,5,0) then // is this really the minimum version? begin MovieName := GetField(fieldOriginalTitle); if MovieName = '' then MovieName := GetField(fieldTranslatedTitle); if Input('MovieMeter.nl Import', 'Geef de titel van de film:', MovieName) then begin AnalyzeResultsPage('http://moviemeter.nl/?search&q='+UrlEncode(MovieName)); end; end else ShowMessage('Dit script vereist een nieuwere versie van Ant Movie Catalog (minstens versie 3.5.0)'); end.